using System.Windows.Forms;
using System.Xml;

using GSN.Config;
using GSNConf.Senders.ConfigControls;
using GSNConf.GenConfigControls;

namespace GSNConf.Senders
{
    class ICQSMSSenderConfigurator : IDictionaryConfigurator
    {
        public ICQSMSSenderConfigurator()
        {
            
        }

        /*public ICQSMSSenderConfigurator(XmlDocument configDoc)
        {
            XmlNode node = configDoc.SelectSingleNode("GSN/Settings/SMS/Username");
            if (node != null)
                setItemString(node.InnerText, "Username");

            // password encrypted?
            bool enc = false;

            node = configDoc.SelectSingleNode("GSN/Settings/PasswordsEncrypted");
            if (node != null)
            {
                enc = bool.Parse(node.InnerText);
            }

            node = configDoc.SelectSingleNode("GSN/Settings/SMS/Password");
            if (node != null)
            {
                if (enc)
                    setItemString(GSN.CryptUtils.decrypt(node.InnerText), "Password");
                else
                    setItemString(node.InnerText, "Password");
            }
        }*/

        public override bool show()
        {
            GenConfigForm form = new GenConfigForm(new ICQSMSSenderConfigControl(), "ICQ Settings");

            ((TextBox)form.Controls.Find("txtIcqUin", true)[0]).Text = getItemString("Username");
            ((TextBox)form.Controls.Find("txtIcqPassword", true)[0]).Text = getItemString("Password");
            ((TextBox)form.Controls.Find("txtIcqServer", true)[0]).Text = getItemString("Server");
            ((MaskedTextBox)form.Controls.Find("txtIcqPort", true)[0]).Text = getItemString("Port");

            if (form.ShowDialog() == DialogResult.OK)
            {
                setItemString(((TextBox)form.Controls.Find("txtIcqUin", true)[0]).Text, "Username");
                setItemString(((TextBox)form.Controls.Find("txtIcqPassword", true)[0]).Text, "Password");
                setItemString(((TextBox)form.Controls.Find("txtIcqServer", true)[0]).Text, "Server");
                setItemString(((MaskedTextBox)form.Controls.Find("txtIcqPort", true)[0]).Text, "Port");

                return true;
            }

            return false;
        }

        /*public override string ToString()
        {
            return "ICQ (Free)";
        }*/

    }
}
